13. Searching and pipes (grep, wc)

Searching and pipes (grep, wc)

With the Shell, you can use commands search content in files.

Use the workspace below the video to practice the commands and remember to practice locally in your computer too. You will need to have download dictionary.txt from Downloading (curl) concept

Ud206 016 Shell P10 - Searching And Pipes

Commands

  • grep: "global regular expression print,” processes text line by line and prints any lines which match a specified pattern
  • wc: "short for word count" reads either standard input or a list of files and generates one or more of the following statistics: newline count, word count, and byte count

grep shell dictionary.txt | less

## Workspace

You can use this workspace to test your commands.

Workspace

This section contains either a workspace (it can be a Jupyter Notebook workspace or an online code editor work space, etc.) and it cannot be automatically downloaded to be generated here. Please access the classroom with your account and manually download the workspace to your local machine. Note that for some courses, Udacity upload the workspace files onto https://github.com/udacity, so you may be able to download them there.

Workspace Information:

  • Default file path:
  • Workspace type: repl
  • Opened files (when workspace is loaded): n/a

Looking for ibo

QUESTION:

How many words are there in dictionary.txt that match the pattern ibo?

SOLUTION:

22

What are grep patterns called?

QUESTION:

Research question! You can use grep for more than just matching words. There's a specific term for the patterns that grep lets you use.

Use your favorite search engine and do a little research to find out what those patterns are called.

SOLUTION:

regular expression

Recomendation

The Shell commands can be installed or not on your computer if you are using Linux or Mac and you have issues running the commands check the documentation specifically for the Operating System.